function [th_min,th_one,th_two,density_one,density_two]=findRightThoSubjs(cond_one,cond_two,th)

[nSubjs,nch,nch1]=size(cond_one);
%th=0.05:0.005:0.15;
nTh=length(th);

connected_one=zeros(nSubjs,nTh);
connected_two=zeros(nSubjs,nTh);
nEdge_one=zeros(nSubjs,nTh);
nEdge_one=zeros(nSubjs,nTh);
for i=1:nSubjs
    [connected_one(i,:),Ci_one,Q_one,nEdge_one(i,:)]=spotThreshold(squeeze(cond_one(i,:,:)),th);
    [connected_two(i,:),Ci_two,Q_two,nEdge_two(i,:)]=spotThreshold(squeeze(cond_two(i,:,:)),th);
end

indx_one=find((sum(connected_one,1)==nSubjs),1,'last');
indx_two=find((sum(connected_two,1)==nSubjs),1,'last');
th_one=th(indx_one);
th_two=th(indx_two);
th_min=min(th_one,th_two);

nMaxEdges=((nch*nch)-nch)/2;
density_one=nEdge_one(:,indx_one)./nMaxEdges;
density_two=nEdge_two(:,indx_two)./nMaxEdges;



